#include <QFileDialog>
#include <QMessageBox>
#include "mainwindow.h"
#include "ui_mainwindow.h"

#include "findCircleParameter.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::clickChooseBtn()
{
    QString fileName = QFileDialog::getOpenFileName(
                this,
                tr("Choose Images"),
                NULL,// ".",
                tr("Images ( *.png *.bmp *.jpg"));
    if(fileName.isEmpty())
    {
        return;
    }
    else
    {
        QPixmap image;
        if(!(image.load(fileName))) //加载图像
        {
            QMessageBox::information(this,
                                     tr("Error"),
                                     tr("打开图像失败!"));
            return;
        }
        ui->label_2->setPixmap(image); //显示图像
        selectFilePath = fileName;
        ui->label->setText(selectFilePath);
    }
}

void MainWindow::clickStartBtn()
{
    Mat source_image = cv::imread(selectFilePath.toStdString());
    ui->label_8->setText(QString::number(source_image.cols));
    ui->label_9->setText(QString::number(source_image.rows));

    if (findCircleParameter::init(source_image))
    {
        findCircleParameter::findCircle();
        Point2i centerPos;
        int r;
        findCircleParameter::getCircleParatemer(centerPos, r);
        ui->label_10->setText(QString::number(centerPos.x));
        ui->label_11->setText(QString::number(centerPos.y));
        ui->label_12->setText(QString::number(r));
    }
}
